// import io from 'socket.io-client'
// import moment from 'moment'
export default {
  namespaced: true,
  state: {
    socket: null, // 放箱服务
    newExportBox: {} // 新出口箱子
  },
  mutations: {},
  actions: {
    // 初始化放箱
    initPutBox ({state, rootState, dispatch}) {
      // 初始化服务
      dispatch('initSocket')
    },
    // 初始化服务
    initSocket ({state, rootState, dispatch}) {
      const [userId] = [rootState.user.uid]
      state.socket = new WebSocket('ws://47.101.133.86:86/websocket/' + userId)
      state.socket.onopen = function (evt) {
        console.log('链接打开')
      }
      state.socket.onmessage = function (evt) {
        console.log(evt, '123123')
        let dataOb = JSON.parse(evt.data)
        let data = dataOb.common[0]
        state.newExportBox = data
      }
      // state.socket = io('http://47.101.133.38:225', {
      //   query: {
      //     uid: userId
      //   }
      // })
      // state.socket.on('connect', () => {})
      // state.socket.on('disconnect', () => {})
      // state.socket.on('new_export_box', ({senderId, timestamp, msg}) => {
      //   state.newExportBox = {senderId, timestamp, msg}
      // })
    }
    // 发送出口放箱数据
    // sendExportBox ({state}, {receiverId, timestamp, message}) {
    //   state.socket.emit('new_export_box', {receiverId, timestamp, message})
    // },
    // 修改出口放箱状态
    // updateExportBoxState ({state}, {receiverId, status}) {
    //   const timestamp = moment().valueOf()
    //   state.socket.emit('update_box_status', {receiverId, timestamp, status})
    // }
  }
}
